from rest_framework import viewsets

from .models import Cart
from .serializers import CartSerializer


class CartView(viewsets.ModelViewSet):
    queryset = Cart.objects.all()
    serializer_class = CartSerializer

    def get_queryset(self):
        qs = super(CartView, self).get_queryset()
        qs = qs.filter(buyer=self.request.user)  # 用户只能看到自己购物车的内容
        return qs
